import java.awt.Button;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

public class GridBagLayoutTest {

	public static void main(String[] args) {
		int gridx, gridy, gridwidth, gridheight, anchor, fill, ipadx, ipady;
		double weightx, weighty;
		Insets insets;

		Frame frm = new Frame("Frame with Controls");
		GridBagLayout gb = new GridBagLayout();
		GridBagConstraints c;
		frm.setLayout(gb);

		Button[] btn = new Button[5];

		// Button 1
		btn[0] = new Button("Button 1");
		gridx = 0; gridy = 0;
		gridwidth = 1; gridheight = 1;
		weightx = 10; weighty = 1;
		anchor = GridBagConstraints.CENTER;
		fill = GridBagConstraints.HORIZONTAL;
		insets = new Insets(0, 0, 0, 0);
		ipadx = 0; ipady = 0;
		c = new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
				weightx, weighty, anchor, fill, insets, ipadx, ipady);
		gb.setConstraints(btn[0], c);
		frm.add(btn[0]);

		// Button 2
		btn[1] = new Button("Button 2");
		gridx = 1; gridy = 0;
		gridwidth = 2; gridheight = 1;
		weightx = 1; weighty = 1;
		anchor = GridBagConstraints.CENTER;
		fill = GridBagConstraints.HORIZONTAL;
		insets = new Insets(0, 0, 0, 0);
		ipadx = 50; ipady = 0;
		c = new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
				weightx, weighty, anchor, fill, insets, ipadx, ipady);
		gb.setConstraints(btn[1], c);
		frm.add(btn[1]);

		// Button 3
		btn[2] = new Button("Button 3");
		gridx = 0; gridy = 1;
		gridwidth = 1; gridheight = 1;
		weightx = 1; weighty = 1;
		anchor = GridBagConstraints.CENTER;
		fill = GridBagConstraints.HORIZONTAL;
		insets = new Insets(10, 0, 0, 0);
		ipadx = 50; ipady = 0;
		c = new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
				weightx, weighty, anchor, fill, insets, ipadx, ipady);
		gb.setConstraints(btn[2], c);
		frm.add(btn[2]);

		// Button 4
		btn[3] = new Button("Button 4");
		gridx = 1; gridy = 1;
		gridwidth = 1; gridheight = 1;
		weightx = 1; weighty = 1;
		anchor = GridBagConstraints.CENTER;
		fill = GridBagConstraints.HORIZONTAL;
		insets = new Insets(0, 0, 0, 0);
		ipadx = 0; ipady = 50;
		c = new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
				weightx, weighty, anchor, fill, insets, ipadx, ipady);
		gb.setConstraints(btn[3], c);
		frm.add(btn[3]);

		// Button 5
		btn[4] = new Button("Button 5");
		gridx = 2; gridy = 1;
		gridwidth = 1; gridheight = 2;
		weightx = 1; weighty = 1;
		anchor = GridBagConstraints.SOUTH;
		fill = GridBagConstraints.HORIZONTAL;
		insets = new Insets(0, 0, 0, 0);
		ipadx = 0; ipady = 0;
		c = new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
				weightx, weighty, anchor, fill, insets, ipadx, ipady);
		gb.setConstraints(btn[4], c);
		frm.add(btn[4]);
		
		frm.setBounds(100, 100, 300, 300);
		frm.setVisible(true);
	}
}
